/**
 * 
 */
package la.ge.server.servlets.repository.uploader;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import la.ge.server.GeServer;
import la.ge.server.GeServerContext;

import org.apache.commons.io.IOUtils;

public class UploadUIServlet extends HttpServlet
{
	public UploadUIServlet() {
		// TODO Auto-generated constructor stub
	}
	
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
    	GeServerContext geServerContext = (GeServerContext) this.getServletContext().getAttribute( GeServerContext.ATTRIB_NAME );
        response.setContentType("text/html");
        response.setStatus(HttpServletResponse.SC_OK);
       
        InputStream in = this.getClass().getClassLoader().getResourceAsStream( "upload_dialog_template.html" );
        StringWriter stringWriter = new StringWriter();
        IOUtils.copy( in, stringWriter );
        in.close();
        String resp = stringWriter.toString();
        resp = resp.replace("${PATH}", geServerContext.getServletPath( UploadServlet.class ));
        response.getWriter().println( resp );
        
    }
}